package com.waves.user.controller;


import com.waves.common.domain.dto.PageBaseDTO;
import com.waves.common.domain.vo.PageBaseVO;
import com.waves.core.utils.LoginUtils;
import com.waves.core.web.domain.R;
import com.waves.core.web.domain.TableDataInfo;
import com.waves.core.web.domain.dto.CursorPageBaseDTO;
import com.waves.core.web.domain.vo.CursorPageBaseVO;
import com.waves.user.domain.dto.friend.FriendApplyDTO;
import com.waves.user.domain.dto.friend.FriendApproveDTO;
import com.waves.user.domain.dto.friend.FriendCheckDTO;
import com.waves.user.domain.dto.friend.FriendDeleteDTO;
import com.waves.user.domain.vo.friend.FriendApplyVO;
import com.waves.user.domain.vo.friend.FriendCheckVO;
import com.waves.user.domain.vo.friend.FriendUnreadVO;
import com.waves.user.domain.vo.friend.FriendVO;
import com.waves.user.service.FriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 好友相关接口
 * </p>
 *
 * @author dlw
 * @since 2024-07-16
 */
@RestController
@RequestMapping("/userApi/user/friend")
@Api(tags = "好友相关接口")
@Slf4j
public class FriendController {
    @Resource
    private FriendService friendService;

    @GetMapping("/check")
    @ApiOperation("批量判断是否是自己好友")
    public R<FriendCheckVO> check(@Valid FriendCheckDTO request) {
        return R.ok(friendService.check(request));
    }

    @PostMapping("/apply")
    @ApiOperation("申请好友")
    public R<Void> apply(@Valid @RequestBody FriendApplyDTO request) {
        friendService.apply(request);
        return R.ok();
    }

    @DeleteMapping()
    @ApiOperation("删除好友")
    public R<Void> delete(@Valid @RequestBody FriendDeleteDTO request) {
        friendService.deleteFriend(request.getTargetUid());
        return R.ok();
    }

    @GetMapping("/apply/page")
    @ApiOperation("好友申请列表")
    public R<PageBaseVO<FriendApplyVO>> page(@Valid PageBaseDTO request) {
        return R.ok(friendService.pageApplyFriend(request));
    }

    @GetMapping("/apply/unread")
    @ApiOperation("申请未读数")
    public R<FriendUnreadVO> unread() {
        return R.ok(friendService.unread());
    }

    @PutMapping("/apply")
    @ApiOperation("审批同意")
    public R<Void> applyApprove(@Valid @RequestBody FriendApproveDTO request) {
        friendService.applyApprove(LoginUtils.getUserId(), request);
        return R.ok();
    }

    @GetMapping("/page")
    @ApiOperation("联系人列表")
    public R<CursorPageBaseVO<FriendVO>> friendList(@Valid CursorPageBaseDTO request) {
        return R.ok(friendService.friendList(request));
    }
}

